// pages/myhomepages/myhomepages.js
import baseuser from '~/utils/users.js'
import baseteam from '~/utils/teamleader.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        settop:0,
        applymain:{},
        kefucode:'',
        show: false,
        category:'',
        unitPrice:0,
        commissionRate:0,
        receiptSupport:'',
area:''

    },
    async getcode() {
      let resdata = await baseuser.getcde()
      console.log(resdata)
      this.setData({
          kefucode: resdata.data.item.code
      })
  },

    addmodify() {
      this.setData({
          show: true
      })
  },
  lianxikefu() {
    console.log('000');
      this.setData({
          show: true
      })
    },
  onClose() {
      this.setData({
          show: false
      })
  },
    naveback() {
        setTimeout(() => {
            wx.navigateBack()
        }, 300);
    },
    copydata(items) {
        wx.setClipboardData({
            data: items.currentTarget.dataset.copys,
            success(res) {
                wx.showToast({
                    title: '拷贝成功',
                    icon: 'success',
                    duration: 2000
                })
            }
        })
    },
 
    async gatapplymain(){
        
        let setdata = {
            byUserId:this.data.optionid
        }
        let reqdata = await baseuser.applyhead(setdata)
        console.log('reqdata',reqdata)
        if (reqdata.code == 200) {
            this.setData({
                applymain: reqdata.data.item,
                kefucode: reqdata.data.item.appletHeadApprove.headHelpCode,
                category: reqdata.data.item.needClass,
                unitPrice:reqdata.data.item.customerHighest+'~'+reqdata.data.item.customerLowest+'元',
                commissionRate:reqdata.data.item.commissionHighest+'%~'+reqdata.data.item.commissionLowest+'%',
                area:reqdata.data.item.area,
                
            })
        }else{
            wx.showToast({
                title: '查询失败',
                icon: 'none',
                duration: 2000
            })
            setTimeout(() => {
                this.naveback()
            }, 300);
        }
        
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      this.getcode()
        let Bartop = (0, wx.getMenuButtonBoundingClientRect)().top;
        let BarHeight = (0, wx.getMenuButtonBoundingClientRect)().height;

        console.log(wx.getMenuButtonBoundingClientRect())
        this.setData({
            settop: Bartop + BarHeight * 1.5
        })
        if (JSON.stringify(options) != undefined && JSON.stringify(options).length > 2) {
            this.setData({
                optionid: options.id
            })
            this.gatapplymain()
        } else {
            wx.showToast({
                title: '查询失败',
                icon: 'none',
                duration: 2000
            })
            setTimeout(() => {
                this.naveback()
            }, 300);
        }
    },
    async chengeflow(items){
        let setdata = {
            "beUserId": this.data.applymain.userId,
        }
        let setnewdat = `applymain.isFollow`
        let reqdata = await baseteam.addfollow(setdata)
        if (reqdata.code == 200) {
            wx.showToast({
                title: reqdata.data.data.message,
                icon: 'success',
                duration: 2000
            })
            this.setData({
                [setnewdat]: reqdata.data.data.state
            })
        } else {
            wx.showToast({
                title: '操作失败',
                icon: 'error',
                duration: 2000
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})